import { View } from "../../../mvc/core/View";
import { FlowerBg } from "../common/FlowerBg";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { Language } from "../../../../extend/language/Language";
import { ImagesConst } from "../../resource/ImagesConst";
import { FightSpiritAttView } from "./FightSpiritAttView";
import { ResFileConst } from "../../resource/ResFileConst";
import { CommonBuyPropPart } from "./CommonBuyPropPart";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { Cache } from "../../cache/Cache";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { FightSpiritConfig } from "../../resource/FightSpiritConfig";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { TFightSpiritBreak } from "../../../../Message/Db/Tables/TFightSpiritBreak";
type int = number;
//class FightSpiritBreakPanel
    
    export  class FightSpiritBreakPanel extends View
    {
        constructor()
        {
            super();
            this.initView();
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=new FlowerBg(432, 432);
            addChild(loc1);
            this._stBreakAddBm = ObjCreate.createBitmap("", 10, 10, this);
            this._breakAddTx = ObjCreate.createGTextField("", 340, 7, 80, 40, this, new GTextFormat(FontUtil.stXingkaiName, 24, 65280, true));
            var loc2=ObjCreate.createGTextField("", 10, 36, 400, 44, this);
            loc2.multiline = true;
            loc2.wordWrap = true;
            loc2.htmlText = Language.getString(71135);
            ObjCreate.createBg(8, 82, 390, 2, this, ImagesConst.SplitLine);
            this._stBreakBm = ObjCreate.createBitmap("", 10, 90, this);
            ObjCreate.createBg(8, 119, 201, 183, this);
            ObjCreate.createBg(222, 119, 201, 183, this);
            this._stBreakBeforeBm = ObjCreate.createBitmap("", 80, 125, this);
            this._stBreakAfterBm = ObjCreate.createBitmap("", 287, 125, this);
            this._oldAttSp = new FightSpiritAttView();
            this._oldAttSp.x = 22;
            this._oldAttSp.y = 146;
            addChild(this._oldAttSp);
            this._newAttSp = new FightSpiritAttView();
            this._newAttSp.x = 234;
            this._newAttSp.y = 146;
            addChild(this._newAttSp);
            this._goBreakBtn = ObjCreate.createGLoadedButton(ResFileConst.IntegralShopBtn, 137, 308, 160, 46, this);
            this._goBreakBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGoBreakBtnClick);
            this._btnLabel = ObjCreate.createBitmap("", 183, 320, this);
            ObjCreate.createBg(8, 354, 400, 2, this, ImagesConst.SplitLine);
            ObjCreate.createBg(8, 362, 415, 63, this, ImagesConst.DisabledBg);
            ObjCreate.createBg(339, 371, 70, 22, this, ImagesConst.DisabledBg);
            this._buyPart = new CommonBuyPropPart(ECategory._ECategoryProp, EProp._EPropFightSpiritBreakRune);
            this._buyPart.x = 26;
            this._buyPart.y = 356;
            addChild(this._buyPart);
            var loc3=ObjCreate.createTextField(Language.getString(70023), 297, 373, 34, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createBitmap(ImagesConst.Tongqian_small, 391, 373, this);
            this._txCost = ObjCreate.createTextField("", 347, 372, 54, 20, this, GlobalStyle.textFormat2);
            this._autoBuy = ObjCreate.createCheckBox(Language.getString(54426), 279, 396, 142, 20, this);
            LoaderHelp.addResCallBack(ResFileConst.FightSpirit, this.onLoadBmResource);
            return;
        }

        protected onGoBreakBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            var loc2=0;
            if (this._tbreakInfo) 
            {
                if (!this._autoBuy.selected) 
                {
                    loc1 = this._buyPart.amount;
                    loc2 = Cache.instance.login.loginGame.money.coin + Cache.instance.login.loginGame.money.coinBind;
                    if (loc1 < this._tbreakInfo.materialNum) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(71109));
                        return;
                    }
                    if (loc2 < this._tbreakInfo.money) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(20038));
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, this._tbreakInfo.money));
                        return;
                    }
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.FightSpiritGoBreak, this._autoBuy.selected));
            }
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            this._stBreakAddBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.FightSpiritBreakAddPecent);
            this._stBreakBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.FightSpiritBreak);
            this._stBreakBeforeBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.FightSpiritBreakBefore);
            this._stBreakAfterBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.FightSpiritBreakAfter);
            this._btnLabel.bitmapData = GlobalClass.getBitmapData(ImagesConst.FightSpiritBreakBtn);
            return;
        }

        public updateInfo(arg1: Array<any>): void
        {
            this._oldAttSp.processData(arg1, Cache.instance.role.fightSpiritLevel, Cache.instance.role.fightSpiritBreakLv);
            this._newAttSp.processData(arg1, Cache.instance.role.fightSpiritLevel, Cache.instance.role.fightSpiritLevel);
            this.updateMetarils(Cache.instance.role.fightSpiritLevel);
            return;
        }

        /* internal  */updateMetarils(arg1: int): void
        {
            this._tbreakInfo = FightSpiritConfig.instance.getFightSpiritBreakInfo(arg1);
            this._buyPart.updateNeedCount(this._tbreakInfo.materialNum);
            this._txCost.text = this._tbreakInfo.money.toString();
            this._breakAddTx.text = "+" + Cache.instance.fightSpirit.getSingleBreakLvAddPrecent(Cache.instance.role.fightSpiritLevel) / 100 + "%";
            return;
        }

        public checkPropInPack(): void
        {
            this._buyPart.updatePackData();
            return;
        }

        /* internal */ /* var */_breakAddTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_goBreakBtn: GLoadedButton;

        /* internal */ /* var */_btnLabel: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_oldAttSp: FightSpiritAttView;

        /* internal */ /* var */_newAttSp: FightSpiritAttView;

        /* internal */ /* var */_stBreakAddBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_stBreakBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_stBreakBeforeBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_stBreakAfterBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_buyPart: CommonBuyPropPart;

        /* internal */ /* var */_autoBuy: GCheckBox;

        /* internal */ /* var */_txCost: Object /* flash.text.TextField */;

        /* internal */ /* var */_tbreakInfo: TFightSpiritBreak;
    }
